#include "tools.cpp"

class Solution {
  public:
    static constexpr int offset = 'A' - 'a';
    bool isPalindrome(string s) {
        int left = 0, right = s.size() - 1;
        while (left < right) {
            while (left < right and can_ignore(s[left])) ++left;
            while (left < right and can_ignore(s[right])) --right;
            if (helper(s[left]) != helper(s[right])) return false;
            std::cout << s[left] << ", " << s[right] << std::endl;
            ++left, --right;
        }
        return true;
    }

    bool can_ignore(char c) {
        return not((c <= 'z' and c >= 'a') or (c <= 'Z' and c >= 'A') or (c <= '9' and c >= '0'));
    }

    char helper(char c) {
        if (c <= 'z' and c >= 'a') return c + offset;
        return c;
    }
};

int main() {
    // std::string str{"race a car"};
    std::string str{"A man, a plan, a canal : Panama"};
    Solution s;
    s.isPalindrome(str);
}
